//-----------------------------------------------------------------------------
//
// @file	RugbyIntro.h
// @brief	RugbyIntro functionality
// @author	Vinod Melapudi
// @date	01May2011
//
//-----------------------------------------------------------------------------

 
#ifndef _RUGBYINTRO_H
#define _RUGBYINTRO_H

#include "Scene.h"
#include "Mesh.h"
#include "Texture.h"
#include "Quaternion.h"
#include "Mesh.h"


class RugbyIntro: public Scene
{
public:
	RugbyIntro();
	~RugbyIntro();

	bool Init();
	void Update();
	void Render( Renderer* renderer );
	bool HandleMessage( UINT msg, WPARAM wParam, LPARAM lParam );
	void UnInit();

private:
	void InitStars();
	void RenderStars();

	void InitPlanets();
	void RenderPlanets();

	void InitGases();
	void RenderGases();

	void InitMap();
	void UpdateMap();
	void RenderMap();

	void InitCamAnim();
	void UpdateCamAnim();
	void RenderCamTrace();

private:

	struct CamAnimCmd
	{
		enum Command
		{
			ZOOM,
			PAN,
			ROTATE,
			ROTATE_AND_ZOOM,
			ROTATE_AND_PAN
		};

		Command cmd;
		int		repeat;		// Number of times to execute this command consecutively
		float	params[5];	// Zoom		: z,
							// Pan		: x,y
							// Rotate	: axis, angle
							// RotateAndZoom: axis, angle, z
							// RotateAndZoom: axis, angle, x,y
	
		CamAnimCmd( Command c, int r, float p1, float p2=0.0f, float p3=0.0f, float p4=0.0f, float p5=0.0f, float p6=0.0f )
		{
			cmd = c;
			repeat = r;
			params[0] = p1;
			params[1] = p2;
			params[2] = p3;
			params[3] = p4;
			params[4] = p5;
			params[5] = p6;
		}
	};

	// Planet/Gas sphere
	struct Sphere
	{
		GLUquadricObj*	sphere;
		Texture*		texture;
		Vector3			position;
		Quaternion		rotation;
		float			radius;
	};

	// Map for NZ map
	struct Map
	{
		Mesh					mesh;
		std::vector<Texture*>	textures;
		int						current_texture;
		Vector3					position;
		Quaternion				rotation;
		Vector3					scale;

		enum STATE
		{
			OFF,
			FADEIN,
			ON,
			FADEOUT
		};
		STATE					state;
		float					max_fade_time;
		float					curr_fade_time;
	};


	std::vector<Texture*>	m_textures;
	float*					m_star_points;
	std::vector<Sphere>		m_planets;
	std::vector<Sphere>		m_gases;
	Map						m_map;

	// Camera anim commands
	std::vector<CamAnimCmd> m_cam_anim;					// Cam anim cmds
	bool					m_animate_camera;				// Flag to switch to animating camera
	int						m_current_cam_anim_cmd;			// Current cmd thats executed
	int						m_current_cam_anim_cmd_num_exec;	// Num of execution of current cmd
	std::vector<Vector3>	m_cam_trace;					// Tracing camera position

	// Flags
	bool	m_render_stars;
	bool	m_render_planets;
	bool	m_render_gas;
	bool	m_render_map;
	bool	m_render_cam_trace;
};

#endif